<html>
<head>
	<title>修改密码</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<script src="../../static/bootstrap/js/jquery-3.4.1.min.js" type="text/javascript"></script>
	<script src="../../static/bootstrap/js/static-resources.js"></script>
</head>
<script type="text/javascript">
	$(function () {
		$(".footerPage").load("../footer.html");
		let DEFAULT_DATA_MODEL = {
			"actorno": "",
			"enname": "",
			"actorname": "",
		};
		new Vue({
			el: '#app',
			mixins: [window.$DEFAULT_MIXIN],
			data: {
				readonly: false,
				loading: false,
				modelTitle: "",
				dataObj: {
					password: "",
					newPassword: "",
					confirmPassword: "",
				},
				opType: "",
			},
			watch: {
			},
			computed: {
				paths() {
					return [
						{text: '首页', href: '/index.html'},
						{text: '系统管理', href: '#'},
						{text: '组织机构', href: '#'},
						{text: '用户管理', href: 'admin/SUserList.html'},
					]
				},
			},
			methods: {

				resetContent() {
					this.dataObj.password = "";
					this.dataObj.newPassword = "";
					this.dataObj.confirmPassword = "";
				},
				saveInfo() {
					if (this.dataObj.newPassword != this.dataObj.confirmPassword) {
						this.$bvToast.toast("两次输入的密码不一致", {
							title: '提示 ',
							toaster: 'b-toaster-top-center',
							solid: true
						});
						return ;
					}

					let requestOptions = {
						url: "api/account/modifyUserPwd",
						type: "POST",
						dataObj: this.dataObj,
						success: (data) => {
							this.$bvToast.toast("密码修改成功", {
								title: '提示 ',
								toaster: 'b-toaster-top-center',
								solid: true
							});
							this.loading = false;
							this.closeModel();
						},
						error: (jqXHR, textStatus, errorThrown) => {
							this.loading = false;
							this.$bvToast.toast("密码修改失败", {
								title: '提示 ',
								toaster: 'b-toaster-top-center',
								solid: true
							});
						}
					};

					this.loading = true;
					let self = this;
					this.$refs.form.validate().then(success => {
						if (!success) {
							this.loading = false;
							return;
						}
						JLEUtil.request(requestOptions.url, requestOptions.type, null,
								requestOptions.dataObj,
								requestOptions.success,
								requestOptions.error
						);
					});
				},
				closeModel() {
					window.parent.$TOP.show = false;
				}
			},
			mounted() {
			}
		})
	});

</script>
</head>
<body>
<div class="headerPage"></div>
<div id="app">

	<b-container fluid>
		<b-row align-h="center">
			<b-col cols="6">
				<validation-observer ref="form">
					<form role="form">
						<div class="row">
							<div class="col-sm-12">
								<validation-provider name="password" :rules="{ required: true }" v-slot="validationContext">
									<b-form-group label="原密码" label-cols-sm="3" label-align-sm="right">
										<b-form-input type="password" v-model="dataObj.password"
													  :state="getValidationState(validationContext)"
													  name="password" placeholder="原密码"></b-form-input>
										<b-form-invalid-feedback >原密码不能为空</b-form-invalid-feedback>
									</b-form-group>
								</validation-provider>
							</div>
							<div class="col-sm-12">
								<validation-provider name="newPassword" :rules="{ required: true }" v-slot="validationContext">
									<b-form-group label="新密码" label-cols-sm="3" label-align-sm="right">
										<b-form-input type="password" v-model="dataObj.newPassword"
													  :state="getValidationState(validationContext)"
													  name="newPassword" placeholder="新密码"></b-form-input>
										<b-form-invalid-feedback >新密码不能为空</b-form-invalid-feedback>
									</b-form-group>
								</validation-provider>
							</div>
							<div class="col-sm-12">
								<validation-provider name="confirmPassword" :rules="{ required: true }" v-slot="validationContext">
									<b-form-group label="确认密码" label-cols-sm="3" label-align-sm="right">
										<b-form-input type="password" v-model="dataObj.confirmPassword"
													  :state="getValidationState(validationContext)"
													  name="confirmPassword" placeholder="确认密码"></b-form-input>
										<b-form-invalid-feedback >确认密码不能为空</b-form-invalid-feedback>
									</b-form-group>
								</validation-provider>
							</div>
						</div>

					</form>
				</validation-observer>
			</b-col>
		</b-row>



		<div class="control-group col-sm-12">
			<div class="text-center">
				<b-button variant="primary" @click="saveInfo" :disabled="loading">
					<div v-if="loading">
						<b-spinner small></b-spinner>
						保存中...
					</div>
					<span v-else="loading">保存</span>
				</b-button>
				<b-button variant="secondary" @click="closeModel" :disabled="loading">返回</b-button>
			</div>
		</div>
	</b-container>


</div>
<div class="footerPage"></div>
</body>
</html>